package com.lry.basic.redis;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.Tuple;

import java.util.Set;

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class ZsetApply {

    private Jedis jedis;

    @BeforeAll
    public void before(){
        jedis = RedisPool.getJedis();
    }

    @AfterAll
    public void after(){
        RedisPool.release(jedis);
    }

    //排行榜，延时队列
    //成绩榜，按照成绩排名
    //视频榜，按照时间，点赞，观看数
    //交并集
    @Test
    public void testRank(){
        String userScoreRank = "user:score:rank";
        jedis.zadd(userScoreRank,90,"a");
        jedis.zadd(userScoreRank,92,"b");
        jedis.zadd(userScoreRank,91,"c");
        Set<Tuple> set = jedis.zrangeByScoreWithScores(userScoreRank,0,100,0,10);
        for(Tuple tuple:set){
            System.out.println(tuple.getElement());
            System.out.println(tuple.getScore());
        }
        //只看前十名
        set=  jedis.zrevrangeWithScores(userScoreRank,0,10);
        for(Tuple tuple:set){
            System.out.println(tuple.getElement());
            System.out.println(tuple.getScore());
        }
    }



}
